package cc.bailongma.me.view;

import cc.bailongma.me.R;
import cc.bailongma.me.entity.Parent;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class AddParentDialog extends AlertDialog implements android.view.View.OnClickListener{
	private EditText chengwei;
	private EditText phone;
	private MyDialogListener listener;
	private Context context;
	public AddParentDialog(Context context,MyDialogListener listener) {
		super(context);
		this.listener=listener;
		this.context=context;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		View view=LayoutInflater.from(context).inflate(R.layout.add_parent_number_dialog, null);
		chengwei=(EditText) view.findViewById(R.id.et_chengwei);
		phone=(EditText) view.findViewById(R.id.et_phone);
		view.findViewById(R.id.tv_cancle).setOnClickListener(this);
		view.findViewById(R.id.tv_father).setOnClickListener(this);
		view.findViewById(R.id.tv_mother).setOnClickListener(this);
		view.findViewById(R.id.tv_grandfather).setOnClickListener(this);
		view.findViewById(R.id.tv_grandmother).setOnClickListener(this);
		view.findViewById(R.id.tv_teacher).setOnClickListener(this);
		view.findViewById(R.id.tv_uncle).setOnClickListener(this);
		view.findViewById(R.id.tv_aunt).setOnClickListener(this);
		view.findViewById(R.id.tv_meternal_grandfather).setOnClickListener(this);
		view.findViewById(R.id.tv_meternal_grandmother).setOnClickListener(this);
		view.findViewById(R.id.tv_classmate).setOnClickListener(this);
		view.findViewById(R.id.tv_submit).setOnClickListener(this);
		setContentView(view);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.tv_cancle:
			this.dismiss();
			break;
		case R.id.tv_submit:
			addParent();
			break;
		case R.id.tv_father:
		case R.id.tv_mother:
		case R.id.tv_grandfather:
		case R.id.tv_grandmother:
		case R.id.tv_teacher:
		case R.id.tv_uncle:
		case R.id.tv_aunt:
		case R.id.tv_meternal_grandfather:
		case R.id.tv_meternal_grandmother:
		case R.id.tv_classmate:
			setText(v);
			break;
		}
	}

	private void addParent() {
		Parent parent=new Parent(100, chengwei.getText().toString(), phone.getText().toString(), false);
		listener.onOkClick(parent);
		dismiss();
	}

	private void setText(View v) {
		TextView tv=(TextView)v;
		chengwei.setText(tv.getText().toString());
	}
	
	public interface MyDialogListener {
	    public void onOkClick(Parent parent);
	    public void update();
	}
}
